package cn.com.yang.aop;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import cn.com.yang.utils.StringUtils;

/**
 * 
 * TODO
 * @author yangyijin
 * @since 2023年4月3日-下午6:07:35
 */
//@Aspect
//@Component
public class DeSm4Aop {
	private static Logger logger = LoggerFactory.getLogger(DeSm4Aop.class);
	
//	@Before("execution(* cn.com.yang.dao.IbatisDao.insert(*,*))")
	public void beforeAddCustInfo(JoinPoint joinPoint) {
		String methodName = joinPoint.getSignature().getName();
		Object[] args =  joinPoint.getArgs();
		if(args!=null) {
			List<Object> list = Arrays.asList(args);
			for (Object obj : list) {
				dealObj(obj);
			}
		}
	}
	
	private void dealObj(Object obj) {
		if(obj instanceof Map) {
			Map map = (Map)obj;
			if(StringUtils.isNotEmpty((String) map.get("CUST_MOBILE"))) {
				
			}
		}
	}

//	@Before("execution(* com.yang.dao.IbatisDao.update(*,*))")
	public void beforeUpdateCustInfo(JoinPoint joinPoint) {
		String methodName = joinPoint.getSignature().getName();
		Object[] args =  joinPoint.getArgs();
		if(args!=null) {
			List<Object> list = Arrays.asList(args);
			for (Object obj : list) {
				logger.info("obj:{}",obj);
			}
		}
	}
	
//	@Around("execution(* cn.com.yang.dao.IbatisDao.query*(*,*))")
	public void afterSelCustInfo(ProceedingJoinPoint joinPoint) {
		String methodName = joinPoint.getSignature().getName();
		if("queryForMap".equals(methodName)) {
			Object[] args =  joinPoint.getArgs();
			try {
				Object obj = joinPoint.proceed(); //获取返回值
				if(obj instanceof Map) {
					Map map = (Map)obj;
					if(StringUtils.isNotEmpty((String) map.get("CUST_MOBILE"))) {
						
					}
				}
				logger.info("obj:{}",obj);
			} catch (Throwable e) {
				e.printStackTrace();
			}
		
		}
	}
	//如果有返回值 使用ProceedingJoinPoint @Around
}
